package at.dcmspl;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.*;

/**
 * Represents a DicomFile
 * @author Hannes Stornig, Gosch Daniel
 */
@Entity
public class DcmFile implements Serializable {
    private static final long serialVersionUID = 1L;
    private String name;
    private String dateiname;

    @Version
    int versionsnr;
    @Temporal(TemporalType.TIMESTAMP)
    Date angelegtAm;
    @ManyToOne
    DcmQueueSimple angelegtVon;
    @Temporal(TemporalType.TIMESTAMP)
    Date zuletztGeaendertAm;
    @ManyToOne
    DcmQueueSimple zuletztGeaendertVon;
    
    @PrePersist public void erzeugungsattributeSetzen(){
        angelegtAm = new Date();
        angelegtVon = parentDcmQueue;
    }
    
    @PreUpdate public void aenderungsattributeSetzen(){
        zuletztGeaendertAm = new Date();
        zuletztGeaendertVon = parentDcmQueue;
    }
    
    @ManyToOne(optional=false)
    @JoinColumn(name="dcmqueuesimple_id")
    private DcmQueueSimple parentDcmQueue;
    
    /**
    * Getter for DcmQueue
    * @return DcmQueueSimple
    */
    public DcmQueueSimple getDcmqueue() {
        return parentDcmQueue;
    }
    
    /**
    * Setter for DcmQueue
    * 
    */
    public void setDcmqueue(DcmQueueSimple dcmqueue) {
        this.parentDcmQueue = dcmqueue;
    }
    
    /**
    * Constructors
    * 
    */
    public DcmFile() {
    }

    public DcmFile(String name, String dateiname, DcmQueueSimple dcmQueue) {
        this.name = name;
        this.dateiname = dateiname;
        this.parentDcmQueue = dcmQueue;
    }
    
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
    
    public String getDateiname() {
        return dateiname;
    }

    public void setDateiname(String dateiname) {
        this.dateiname = dateiname;
    }

    public Date getAngelegtAm() {
        return angelegtAm;
    }

    public DcmQueueSimple getAngelegtVon() {
        return angelegtVon;
    }

    public DcmQueueSimple getParentDcmQueue() {
        return parentDcmQueue;
    }

    public int getVersionsnr() {
        return versionsnr;
    }

    public Date getZuletztGeaendertAm() {
            return zuletztGeaendertAm;
    }

    public DcmQueueSimple getZuletztGeaendertVon() {
        return zuletztGeaendertVon;
    }
    
     
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof DcmFile)) {
            return false;
        }
        DcmFile other = (DcmFile) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "at.dcmspl.DcmFile[ id=" + id + " name " + name + " ]";
    }
    
}
